package com.yanqu.road.server.cmd.activity.evefeast;

import com.yanqu.road.entity.activity.evefeast.EveFeastGameData;
import com.yanqu.road.entity.activity.evefeast.UserEveFeastData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.EveFeastProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.evefeast.EveFeastModule;
import com.yanqu.road.server.manger.activity.evefeast.EveFeastMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import org.apache.regexp.RE;

@Cmd(code = GameProtocol.S_EVEFEAST_GET_GUIDE_MSG, desc = "请求引导数据")
public class EveFeastGetGuideMsgCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        EveFeastProto.EveFeastGetGuideReqMsg reqMsg = EveFeastProto.EveFeastGetGuideReqMsg.parseFrom(packet.getBytes());
        if (EveFeastMgr.getConfig() == null || EveFeastMgr.getActivityInfo().getActivityId() != reqMsg.getActivityId()){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        EveFeastProto.EveFeastGetGuideRespMsg.Builder respMsg = EveFeastProto.EveFeastGetGuideRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.addAllResult(EveFeastMgr.getGuideMsgList());
        player.sendPacket(ClientProtocol.U_EVEFEAST_GET_GUIDE_MSG, respMsg);

        EveFeastGameData initGameData = EveFeastMgr.getInitGameData().clone();
        UserEveFeastData userData = player.getModule(EveFeastModule.class).getUserData();
        if (userData != null && userData.getGuideStep() == 0 && userData.getPracticeData() == null) {
            userData.setPracticeData(initGameData);
            userData.setGuideStep(1);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0) {
            player.sendPacket(ClientProtocol.U_EVEFEAST_GET_GUIDE_MSG, EveFeastProto.EveFeastGetGuideRespMsg.newBuilder().setRet(ret));
        }
    }
}
